package com.wnxy.portal.config;

import com.wnxy.portal.common.constant.RedisConstant;
import com.wnxy.portal.entity.Book;
import com.wnxy.portal.entity.China;
import com.wnxy.portal.model.vo.BookVo;
import com.wnxy.portal.service.IBookService;
import com.wnxy.portal.service.IChinaService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class InitChinaAddressRunner implements CommandLineRunner {

    @Autowired
    private IChinaService chinaService;
    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public void run(String... args) throws Exception {
        if (!redisTemplate.hasKey(RedisConstant.CHINA_CACHE)) {
            List<China> list = chinaService.list();
            list.forEach(china -> {
                redisTemplate.opsForHash().put(
                        RedisConstant.CHINA_CACHE, china.getId().toString(), china.getName());
            });
        }
    }
}













